package com.zys.http;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.zys.http.extension.service.Bundle;
import com.zys.http.window.environment.EnvironmentWindow;
import com.zys.http.window.history.HistoryWindow;
import com.zys.http.window.request.RequestWindow;
import jdk.jfr.Description;
import org.jetbrains.annotations.NotNull;

/**
 * @author zys
 * @since 2023-08-13
 */
@Description("创建 ToolWindow 工厂")
public class HttpMainWindowFactory implements ToolWindowFactory {
    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        createContent(toolWindow, new RequestWindow(project), Bundle.get("http.window.tab.api"));
        createContent(toolWindow, new EnvironmentWindow(project), Bundle.get("http.window.tab.env"));
        createContent(toolWindow, new HistoryWindow(project), Bundle.get("http.window.tab.history"));
    }

    private static void createContent(ToolWindow toolWindow, SimpleToolWindowPanel targetPanel, String name) {
        ContentFactory contentFactory = ContentFactory.getInstance();
        Content content = contentFactory.createContent(targetPanel, name, false);
        toolWindow.getContentManager().addContent(content);
    }
}
